import {
  INCREMENTCOUNT,
  DECREMENTCOUNT
} from '../constant/countConstant'
//定义reducer的初始值
const init = {
    count: 0
  }
  export default function countReducer(prevState = init, action) {
    console.log("reducer调用了");
    //接收action对象的type和data
    const{
      type,
      data
    }= action;
    
    switch (type) {
      case INCREMENTCOUNT:
        return {
          ...init, count: prevState.count + data
        };
  
      case DECREMENTCOUNT:
        return {
          ...init, count: prevState.count - data
        }
    }

    return prevState;
  }